import mineflayer from "mineflayer";
import { mcdata, mcVersion } from "../botInit.js";
import prismarineEntity from "prismarine-entity";

export function getNearbyEntities(
  bot: mineflayer.Bot,
  maxDistance: number = 16
): Array<prismarineEntity.Entity> {
  let entities = [];
  for (const entity of Object.values(bot.entities)) {
    const distance = entity.position.distanceTo(bot.entity.position);
    if (distance > maxDistance) continue;
    entities.push({ entity: entity, distance: distance });
  }
  entities.sort((a, b) => a.distance - b.distance);
  let res = [];
  for (const e of entities) res.push(e.entity);
  return res;
}

// 通过名字获取物品的数组id
export function getBlockId(blockName: string): number | null {
  const block = mcdata.blocksByName[blockName];
  if (block) return block.id;
  return null;
}

export function getBiomeName(bot: mineflayer.Bot): string {
  return mcdata.biomes[bot.world.getBiome(bot.entity.position)]?.name ?? "未知";
}
